//
// Created by jsjxsy on 2022/8/12.
// 练习题 11.9 C prime plus
// 反转字符串
//
#include <stdio.h>
#include <string.h>
void swap(char *arr, int i, int j) {
  char temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
}
void reverse(char *arr, const int size) {
  if (size < 2) {
    return;
  }
  for (int i = 0; i < size / 2; i++) {
    swap(arr, i, size - 1 - i);
  }
}
void test(char *arr) {
  printf("arr = %s\n", arr);
  printf("arr size : %lu\n", strlen(arr));
  reverse(arr, strlen(arr));
  printf("arr = %s\n", arr);
}
char *s_gets(char *st, int n);

int main(void) {
//  char str[4][10] = {"abc", "abcd", "12345", "!@#"};
//  for (int i = 0; i < 4; i++) {
//    test(str[i]);
//  }
  char str2[10];
  while (strcmp(s_gets(str2, 10), "quit") != 0) {
    test(str2);
  }
  return 0;
}

char *s_gets(char *st, int n) {
  int i = 0;

  printf("Input the first string (type quit to quit):\n");
  if (fgets(st, n, stdin))    //即返回值st不等于NULL
  {
    while (st[i] != '\n' && st[i] != '\0')
      i++;
    if (st[i] == '\n')
      st[i] = '\0';
  }

  return st;
}